<template>
  <div>
    <!--首页头部区域 -->
    <home-header></home-header>
    <!--轮播区域 -->
    <home-swiper :swiper="swiperList"></home-swiper>
    <!--图标区域 -->
    <home-icons :icons="iconList"></home-icons>
    <!--推荐区域 -->
    <home-recommend :recommend="recommendList"></home-recommend>
    <!--周末去哪区域 -->
    <home-weekend :weekend="weekendList"></home-weekend>
  </div>
</template>

<script>
import HomeHeader from './HomeHeader'
import HomeSwiper from './HomeSwiper'
import HomeIcons from './HomeIcons'
import HomeRecommend from './HomeRecommend'
import HomeWeekend from './HomeWeekend'

export default {
  data: function () {
    return {
      city: '',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
      lastCity: ''
    }
  },
  mounted: function () {
    this.lastCity = this.$store.state.city
    this.getHomeList()
  },
  methods: {
    getHomeList: async function () {
      var { data: res } = await this.$http.get('/api/index.json')
      if (res.ret && res.data) {
        this.city = res.city
        this.swiperList = res.data.swiperList
        this.iconList = res.data.iconList
        this.recommendList = res.data.recommendList
        this.weekendList = res.data.weekendList
      }
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  activated () {
    if (this.lastCity !== this.$store.state.city) {
      this.lastCity = this.$store.state.city
      this.getHomeList()
    }
  }
}
</script>

<style lang="stylus" scoped>

</style>
